package com.central.apps.dao.inspection;


import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface InspplanDao {
    @Select("SELECT c.assetnum AS assetnum,c.assetdesc AS assetdesc,c.inspnum AS inspnum,c.inspdesc AS inspdesc \n" +
            "FROM gq_inspregion a \n" +
            "LEFT JOIN gq_insparealocation b ON a.insaenum = b.insaenum\n" +
            "LEFT JOIN gq_insparealine c ON b.id = c.insplocid\n" +
            "WHERE a.insaenum = #{insaenum}")
    List<Map<String, Object>> getInspplanHandler(@Param("insaenum") String insaenum);
    @Insert("INSERT INTO gq_planasset (planareaid,assetnum,assetdesc,inspnum,inspdesc) VALUES(#{map.planareaid},#{map.assetnum},#{map.assetdesc},#{map.inspnum},#{map.inspdesc})")
    int insert(@Param("map") Map<String, Object> map);


    /**
     * 查今日需要生成的定时任务
     */
    @Select("select * from gq_inspplan where nextexecutedate = #{nextexecutedate}")
    List<Map<String, Object>> findInspplanList(@Param("nextexecutedate") String dateStr);

    /**
     * 根据计划编码查计划区域
     */
    @Select("select * from gq_planarea where inspplannum= #{inspplannum}")
    List<Map<String, Object>> findPlanareaListByInspplannum(String inspplannum);

    /**
     * 根据区域id查资产
     */
    @Select("select * from gq_planasset where planareaid = #{id}")
    List<Map<String, Object>> findPlanassetListByPlanareaid(String id);

    /**
     * 更新点检计划中下次执行时间和上次执行时间
     */
    @Update("update gq_inspplan set nextexecutedate = #{nextexecutedate}, lastexecutedate = #{lastexecutedate} where id = #{id}")
    void updateExecutedate(String nextexecutedate, String lastexecutedate, String id);
}
